package ar.edu.unq.wannaplay.pages.abm;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.link.Link;

import ar.edu.unq.wannaplay.components.WPLink;

public abstract class WPABM<T, P extends WebPage> extends WebPage {
    private static final long serialVersionUID = 1L;

    private Class<P> myResponsePage;

    private T abmObject;

    protected WPABM(final Class<P> response, final T abmObject) {
        this.myResponsePage = response;
        this.abmObject = abmObject;
    }
    
    protected WPABM(final Class<P> response){
    	this.myResponsePage = response;
    }

    /**
     * Agrega los botones aceptar y cancelar
     * Se debe declarar en cada clase que extienda una accion de aceptar
     * La accion de cancelar vuelve a la pagina anterior
     */
    protected void addButtons() {
        this.add(new Link<WebPage>("accept") {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClick() {
                WPABM.this.accept();
                this.setResponsePage(WPABM.this.getMyResponsePage());
            }
        });
        this.add(new WPLink("cancel", this.getMyResponsePage()));
    }

    protected abstract void accept();

    // setters&getters
    protected void setMyResponsePage(final Class<P> responsePage) {
        this.myResponsePage = responsePage;
    }

    protected Class<? extends WebPage> getMyResponsePage() {
        return myResponsePage;
    }

    protected void setAbmObject(final T abmObject) {
        this.abmObject = abmObject;
    }

    protected T getAbmObject() {
        return abmObject;
    }
}
